package jnpf.service.impl;

import jnpf.entity.Whut_channelmmEntity;
import jnpf.mapper.Whut_channelmmMapper;
import jnpf.service.Whut_channelmmService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.util.RandomUtil;


import jnpf.model.whut_channelmm.Whut_channelmmPagination;
import java.util.stream.Collectors;





import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.text.SimpleDateFormat;
import jnpf.util.*;
import java.util.*;

/**
 *
 * whut_channelmm
 * 版本： V3.2.0
 * 版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * 作者： JNPF开发平台组
 * 日期： 2024-10-01
 */
@Service

public class Whut_channelmmServiceImpl extends ServiceImpl<Whut_channelmmMapper, Whut_channelmmEntity> implements Whut_channelmmService {

    @Autowired
    private UserProvider userProvider;






    @Override
    public List<Whut_channelmmEntity> getList(Whut_channelmmPagination whut_channelmmPagination){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
        int total=0;
                    QueryWrapper<Whut_channelmmEntity> whut_channelmmQueryWrapper=new QueryWrapper<>();
            int whut_channelmmNum =0;
			if(StringUtil.isNotEmpty(whut_channelmmPagination.getCode())){
            whut_channelmmNum++;
            whut_channelmmQueryWrapper.lambda().like(Whut_channelmmEntity::getCode,whut_channelmmPagination.getCode());
                    }

			if(StringUtil.isNotEmpty(whut_channelmmPagination.getName())){
            whut_channelmmNum++;
            whut_channelmmQueryWrapper.lambda().like(Whut_channelmmEntity::getName,whut_channelmmPagination.getName());
                    }

        if(AllIdList.size()>0){
            whut_channelmmQueryWrapper.lambda().in(Whut_channelmmEntity::getId, AllIdList);
        }
        //排序
        if(StringUtil.isEmpty(whut_channelmmPagination.getSidx())){
        whut_channelmmQueryWrapper.lambda().orderByDesc(Whut_channelmmEntity::getId);
        }else{
        whut_channelmmQueryWrapper="asc".equals(whut_channelmmPagination.getSort().toLowerCase())?whut_channelmmQueryWrapper.orderByAsc(whut_channelmmPagination.getSidx()):whut_channelmmQueryWrapper.orderByDesc(whut_channelmmPagination.getSidx());
        }
        if((total>0 && AllIdList.size()>0) || total==0){
        Page<Whut_channelmmEntity> page=new Page<>(whut_channelmmPagination.getCurrentPage(), whut_channelmmPagination.getPageSize());
        IPage<Whut_channelmmEntity> userIPage=this.page(page, whut_channelmmQueryWrapper);
        return whut_channelmmPagination.setData(userIPage.getRecords(),userIPage.getTotal());
        }else{
            List<Whut_channelmmEntity> list = new ArrayList();
            return whut_channelmmPagination.setData(list, list.size());
        }
    }
    @Override
    public List<Whut_channelmmEntity> getTypeList(Whut_channelmmPagination whut_channelmmPagination,String dataType){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
		int total=0;
                    QueryWrapper<Whut_channelmmEntity> whut_channelmmQueryWrapper=new QueryWrapper<>();
            int whut_channelmmNum =0;
			if(StringUtil.isNotEmpty(whut_channelmmPagination.getCode())){
            whut_channelmmNum++;
            whut_channelmmQueryWrapper.lambda().like(Whut_channelmmEntity::getCode,whut_channelmmPagination.getCode());
                    }

			if(StringUtil.isNotEmpty(whut_channelmmPagination.getName())){
            whut_channelmmNum++;
            whut_channelmmQueryWrapper.lambda().like(Whut_channelmmEntity::getName,whut_channelmmPagination.getName());
                    }

		if(AllIdList.size()>0){
        whut_channelmmQueryWrapper.lambda().in(Whut_channelmmEntity::getId, AllIdList);
				}
        //排序
        if(StringUtil.isEmpty(whut_channelmmPagination.getSidx())){
        whut_channelmmQueryWrapper.lambda().orderByDesc(Whut_channelmmEntity::getId);
        }else{
        whut_channelmmQueryWrapper="asc".equals(whut_channelmmPagination.getSort().toLowerCase())?whut_channelmmQueryWrapper.orderByAsc(whut_channelmmPagination.getSidx()):whut_channelmmQueryWrapper.orderByDesc(whut_channelmmPagination.getSidx());
        }
        if("0".equals(dataType)){
            if((total>0 && AllIdList.size()>0) || total==0){
                Page<Whut_channelmmEntity> page=new Page<>(whut_channelmmPagination.getCurrentPage(), whut_channelmmPagination.getPageSize());
                IPage<Whut_channelmmEntity> userIPage=this.page(page, whut_channelmmQueryWrapper);
                return whut_channelmmPagination.setData(userIPage.getRecords(),userIPage.getTotal());
            }else{
                List<Whut_channelmmEntity> list = new ArrayList();
                return whut_channelmmPagination.setData(list, list.size());
            }
        }else{
            return this.list(whut_channelmmQueryWrapper);
        }
    }

    @Override
    public Whut_channelmmEntity getInfo(String id){
        QueryWrapper<Whut_channelmmEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(Whut_channelmmEntity::getId,id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(Whut_channelmmEntity entity){
        this.save(entity);
    }

    @Override
    public boolean update(String id, Whut_channelmmEntity entity){
        entity.setId(id);
        return this.updateById(entity);
    }
    @Override
    public void delete(Whut_channelmmEntity entity){
        if(entity!=null){
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法

}